package com.telsoft.util;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.security.MessageDigest;
import org.apache.commons.codec.binary.Base64;
/**
 *
 * @author rongnk
 */
public class StringUtil {
    public static String fix(String input)
    {
        if(input != null)
        {
            return input;
        }
        else
        {
            return "";
        }
    }
    public static String encrypt(String strValue,String strAlgorithm) throws Exception
    {
            return encrypt(strValue.getBytes(),strAlgorithm);
    }
    public static String encrypt(byte[] btValue,String strAlgorithm) throws Exception
    {
            Base64 bs = new Base64();
            MessageDigest md = MessageDigest.getInstance(strAlgorithm);
            return bs.encodeToString(md.digest(btValue));
    }
    public static String[] stringArrayFactory(int length){
        String[] returnvl = new String[length];
        for(int i = 0; i < length;i++){
            String tmp = new String();
            returnvl[i] = tmp;
        }
        return returnvl;
    }
}
